<div class="container-fluid p-t-15">
  <div class="row">
    <div class="col-lg-12">
    	@if(!$_GPC['op'] || $_GPC['op'] == 'display')
    	<style>
		th{
			text-align: center !important;
		}
		td{
			text-align: center !important;
			white-space: normal !important;
			word-break: break-all !important;
		}
		</style>
    	<div class="panel">
		    <div class="card-body">
                <a style="float: right;" class="btn btn-primary" href="?a=model&op=post">添加模型</a>
		            <table class="table table-hover">
		              <thead>
		                <tr>
			                <th>模型ID</th>
			                <th>模型名称</th>
			                <th>模型标识</th>
			                <th>模型秘钥</th>
			                <th>操作</th>
		                </tr>
		              </thead>
		              <tbody>
		              	@foreach($list as $l)
		                <tr>
		                  <td>{{$l['id']}}</td>
		                  <td>{{$l['title']}}</td>
		                  <td>{{$l['model']}}</td>
		                  <td>{{$l['appkey']}}</td>
		                  <td>
		                    <div class="btn-group">
		                      <a class="btn btn-sm btn-default" href="?a=model&op=post&nid={{$l['id']}}" title="编辑" data-toggle="tooltip">编辑</a>
		                      <a class="btn btn-sm btn-danger" onclick="onwxappDel(this,{{$l['id']}})" title="删除" data-toggle="tooltip" data-loading-text="删除中...">删除</a>
		                    </div>
		                  </td>
		                </tr>
		                @endforeach
		               </tbody>
		            </table>
		     </div>
		</div>
		<script>
		function onwxappDel(obj,id){
			$.confirm({
				title:'温馨提示',
				content: '确定删除吗？',
		        buttons:{
		        	confirm:{ 
		        		text:'确认删除',
		        		btnClass: "btn-primary",
		        		action: function(){
			            	lightyear.loading('show');
			            	$.ajax({
						    	url:"",
						    	type:'post',
						    	data:{nid:id,op:'del'},
						    	success:function(res){
						    		if(res == 1){
						    			$(obj).parent().parent().parent().remove();
						    			lightyear.notify("删除成功", 'success', 2000, '', 'top', 'center');
						    		}else lightyear.notify("删除失败", 'danger', 2000, '', 'top', 'center');
						    		$btn.button("reset");
						    	}
						    });
			            },
		        	},
		        	cancel:{text:'取消'}
		        }
			});
		}
		</script>
    	@elseif ($_GPC['op'] == 'post')
	    <form action="#!" method="post" name="edit-form" class="form form-horizontal">
	       <div class="card">
		        <div class="card-header bg-primary">
		          <h4>模型设置</h4>
		        </div>
		        <div class="card-body">
					 <div class="form-group">
			           	<label class="col-xs-12 col-sm-3 col-md-2 control-label">模型名称</label>
			           	<div class="col-sm-9">
			              	 <input required="required" id='title' type="text" name="title" class="form-control" value="{{$item['title']??''}}" />
			           	</div>
			         </div>
			         <div class="form-group">
			           	<label class="col-xs-12 col-sm-3 col-md-2 control-label">模型标识</label>
			           	<div class="col-sm-9">
			              	 <input required="required" id='model' type="text" name="model" class="form-control" value="{{$item['model']??''}}" />
			           	</div>
			         </div>
			         <div class="form-group">
			           	<label class="col-xs-12 col-sm-3 col-md-2 control-label">模型秘钥</label>
			           	<div class="col-sm-9">
			              	 <input required="required" id='appkey' type="text" name="appkey" class="form-control" value="{{$item['appkey']??''}}" />
			           	</div>
			         </div>
				</div>
			</div>
			<button type="button" onclick='onSubmit()' name='submit' value='1' class="btn btn-primary m-r-5">保 存</button>
	    </form>
	    <script>
    	
		function onSubmit(){
			lightyear.loading('show');
			$.ajax({
				url:"",
				type:'post',
				data:$('form').serialize(),
				success:function(res){
					lightyear.loading('hide');
					if(res == 1){
						lightyear.notify('保存成功', 'success', 1500);
						setTimeout(function(){
							location.href = "?a=model";
						},1500);
					}else lightyear.notify(res, 'danger', 100);
				}
			});
		}
		</script>
	   @endif
    </div>
  </div>
</div>